package com.bogo.dbtable.modelVo.result;

import java.io.Serializable;
import java.util.List;

/**
 * 分页查询封装类
 *
 * @param <T>
 * @author wangcl
 * @version 2017-01-23
 */
public class QueryResult<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    private String tName;
    private List<T> rows;
    private int records;
    private long total;
    private int page;

    public QueryResult() {
    }

    public QueryResult(List<T> dataList, Long total, int pageIndex, int pageSize) {
        if (total == null) {
            total = 0L;
        }
        this.rows = dataList;
        this.records = dataList == null ? 0 : dataList.size();
        this.total = (total + pageSize - 1) / pageSize;
        this.page = pageIndex;
    }

    public QueryResult(List<T> dataList, Long total, int pageIndex, int pageSize, String tName) {
        if (total == null) {
            total = 0L;
        }
        this.tName = tName;
        this.rows = dataList;
        this.records = dataList == null ? 0 : dataList.size();
        this.total = (total + pageSize - 1) / pageSize;
        this.page = pageIndex;
    }

    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public int getRecords() {
        return records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String gettName() {
        return tName;
    }

    public void settName(String tName) {
        this.tName = tName;
    }

    @Override
    public String toString() {
        return "QueryResult{" +
                "tName='" + tName + '\'' +
                ", rows=" + rows +
                ", records=" + records +
                ", total=" + total +
                ", page=" + page +
                '}';
    }
}
